package com.future.lottie.base;

import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewbinding.ViewBinding;

import java.util.ArrayList;
import java.util.List;

/**
 * @author xuchuanting
 * Create on 2020/7/16 12:14
 */
public abstract class BaseAdapter<D, B extends ViewBinding> extends RecyclerView.Adapter<BaseViewHolder<B>> {

    private List<D> mDataList = new ArrayList<>();


    @NonNull
    @Override
    public BaseViewHolder<B> onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new BaseViewHolder<>(getViewBinding(LayoutInflater.from(parent.getContext()), parent, viewType));
    }

    protected abstract B getViewBinding(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent, int viewType);

    public D getItem(int position){
        return mDataList.get(position);
    }

    @Override
    public int getItemCount() {
        return mDataList.size();
    }

    public void addAll(List<D> list) {
        mDataList.addAll(list);
        notifyDataSetChanged();
    }
}
